package com.jsshse.tag;

import java.io.IOException;
import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.jsshse.service.report.RBaseServiceI;

public class reportTableTag extends RequestContextAwareTag {

	
	private static final long serialVersionUID = 1L;
	private static Logger log = Logger.getLogger(reportTableTag.class);
	
	private String reportID;
 

	public void setReportID(String reportID) {
		this.reportID = reportID;
	}

	public String getReportID() {
		return reportID;
	}


	@Override
	protected int doStartTagInternal() throws Exception {
		HttpServletRequest request;
		request = (HttpServletRequest) pageContext.getRequest();
		JspWriter out = pageContext.getOut();
		StringBuffer sb=new StringBuffer();
		RBaseServiceI rBaseService=(RBaseServiceI)this.getRequestContext().getWebApplicationContext().getBean("RBaseService");  
		log.debug(rBaseService);
		
		Map table = rBaseService.queryById(reportID);
		
		String title=table.get("title")!=null?table.get("title").toString():"";
		String icon=table.get("icon")!=null?table.get("icon").toString():"";
		String url=table.get("url")!=null?table.get("url").toString():"";
		String frozen_col=table.get("frozen_col")!=null?table.get("frozen_col").toString():"";
		String col=table.get("col")!=null?table.get("col").toString():"";
		String func=table.get("func")!=null?table.get("func").toString():"";
		
		sb.append("title : '" +title+ "',");
		sb.append("iconCls : '" + icon+ "',");
		sb.append("url : ctx+'" + url + "',");
		sb.append("frozenColumns : [ [ " + frozen_col+ " ]],");
		sb.append("columns : [ [ " + col + " ]],");
		sb.append(func + (func.length() > 0 ? "," : ""));
 
		 
		out.append(sb.toString());  
		out.flush();  
		return 0;
	}

}